package cn.tedu.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
@EnableSwagger2  //开启swagger2
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket createRestApi2(Environment environment) {
        //设置要显示swagger环境  dev为开发环境  test为测试环境 prod为生产环境
        Profiles profiles = Profiles.of("dev","test");
        boolean b = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo2())
                .enable(b)
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.tedu.wx.controller"))
                .paths(PathSelectors.any())
                .build().groupName("C");
    }
    //该分组环境生产中不会显示
    @Bean
    public Docket createRestApi(Environment environment) {
        //设置要显示swagger环境
        Profiles profiles = Profiles.of("dev","test");
        boolean b = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())//调用下面的apiInfo()方法配置个人信息
                .enable(b)  //显示分组
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.tedu.system.controller"))//显示哪个包下的controller
                .paths(PathSelectors.any())
                .build().groupName("B");
    }
    @Bean
    public Docket createRestApi1() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo1())
                 //.enable(false)
                .select()
                .apis(RequestHandlerSelectors.basePackage("cn.tedu.web.controller"))
                .paths(PathSelectors.any())
                .build().groupName("A");//groupName("A")表示此模块命名
                                        //不加groupName("A")方法 默认起名字是default
    }
    //配置swagger信息
    private ApiInfo apiInfo() {
        //作者信息
        Contact contact = new Contact("Kiven", "https://www.huaweijr.com",
                "2213593288@qq.com");
        return new ApiInfo(
                "Kiven",
                "心之所向,素履以往",
                "v1.01",
                "https://www.huaweijr.com",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>());
    }
    //配置swagger信息
    private ApiInfo apiInfo1() {
//作者信息
        Contact contact = new Contact("谢子旗", "https://www.huaweijr.com",
                "2213593288@qq.com");
        return new ApiInfo(
                "谢子旗",
                "我喜欢女生",
                "v1.01",
                "https://www.huaweijr.com",
        contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>());
    }
    //配置swagger信息
    private ApiInfo apiInfo2() {
//作者信息
        Contact contact = new Contact("法外狂徒张三", "https://www.huaweijr.com",
                "2213593288@qq.com");
        return new ApiInfo(
                "法外狂徒张三",
                "我喜欢男生",
                "v1.01",
                "https://www.huaweijr.com",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<>());
    }

}